package main

import (
	"fmt"
	"sync"
	"time"
	"yan-feeorder/common"
)

func doSomeThing(lrun *common.LimitRun, wg *sync.WaitGroup, i int) {
	defer lrun.Signal()
	defer wg.Done()

	time.Sleep(3 * 1e9)
}

func main() {
	wg := &sync.WaitGroup{}
	lrun := common.NewLimitRun(3)

	for i := 0; i < 100; i++ {
		ctms := time.Now()
		lrun.Wait()
		ctme := time.Now()
		fmt.Printf("%0.3fs %s\n", ctme.Sub(ctms).Seconds(), lrun.String())

		wg.Add(1)
		go doSomeThing(lrun, wg, i%3)
	}

	wg.Wait()
}
